//
//  ViewController.swift
//  RentFreeDemo
//
//  Created by youmy on 2018/11/23.
//  Copyright © 2018 youmy. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    var rentView : YMRentFreeView?
    var depositV:YMRentDepositView?
    
    //    lazy var rentView : YMRentFreeView? = {
    //        let rentView = YMRentFreeView(frame: CGRect(x: 0, y: 50, width: ym_screen_width, height: 50))
    //        rentView.delegate = self
    //        rentView.isArrowBtn = true
    //        rentView.setHeaderContent(title: "租金费用")
    //        rentView.setFooterContent(title: "(到期买断费用￥1200.00，买断时支付)")
    //        return rentView
    //    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .groupTableViewBackground
        
        var rentList = [YMRentFreeModel]()

        let arr = resoucearrayFromFile(fileName: "rentfree.json", bundle:bundle)

        for dic in arr {
            let model = YMRentFreeModel(fromDictionary: dic)
            rentList.append(model)
        }

        rentView = YMRentFreeView(frame: CGRect(x: 0, y: 50, width: ym_screen_width, height: 50))
        rentView?.delegate = self
        rentView?.rentList = rentList
        rentView?.isArrowBtn = true
        rentView?.setHeaderContent(title: "租金费用")
        rentView?.setFooterContent(title: "")
        view.addSubview(rentView!)
        
//                depositV = YMRentDepositView(frame: CGRect(x: 0, y: 64, width: ym_screen_width, height: 10))
//                depositV?.name = "需支付金额"
//                depositV?.price = "2106.00"
//                depositV?.des = "(到期买断费用￥1200.00，买断时支付)"
////                depositV?.priceColor = UIColor(valueRGB: 0xff4230, alpha: 1)
//                view.addSubview(depositV!)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        depositV?.des = "还机或买断时，押金可退回或用来支付手机买断金。买断金=签约价值-已付租金总额"
    }
    
}

extension ViewController: YMRentFreeViewDelegate {
    func frameDidChange(view: YMRentFreeView, isExpand: Bool) {
        depositV?.frame.origin.y = (rentView?.frame.maxY ?? 0) + 10
    }
    
}
